<template>
  <div class="merchants-container">
    <div style="background: #faf0e6;opacity: .8;margin-top:-10px;height: 30px">
      <el-row>
        <el-breadcrumb separator-class="el-icon-arrow-right">
          <el-breadcrumb-item :to="{ path: '../shouYe' }"style="margin-left: 30px;margin-top: 8px">首页</el-breadcrumb-item>
          <el-breadcrumb-item style="margin-top: 8px"><i class="el-icon-office-building" aria-hidden="true"></i>业务信息</el-breadcrumb-item>
          <el-breadcrumb-item style="margin-top: 8px"><i class="el-icon-s-custom" aria-hidden="true"></i>商户分类</el-breadcrumb-item>
        </el-breadcrumb><br>
      </el-row>
    </div>
    <el-row>
      <el-form label-width="80px">
        <el-row>
          <el-col :span="8" style="margin-top: 10px">
            <el-form-item label="用户名" label-width="80px">
              <el-input style="height: 8%"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8" style="margin-top: 10px">
            <el-form-item label="用户权限" label-width="80px">
              <el-input></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8" style="margin-top: 10px">
            <el-form-item>
              <el-button type="success" style="background-color: cornflowerblue">
                <i class="fa fa-search" aria-hidden="true"></i>
                搜索Search
              </el-button>
              <!--<el-button type="success" style="background-color: cornflowerblue">搜索</el-button>-->
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-row>
    <el-row>

      <el-button-group>

        <el-button @click="btnAddClick" type="primary" icon="el-ico-edit" style="text-align: center">
          <i aria-hidden="true" class="fa fa-plus">添加</i>
        </el-button>

        <el-button type="warning">
          <i  aria-hidden="true" class="fa fa-pencil-square-o">修改</i></el-button>

        <el-button type="danger" >
          <i aria-hidden="true" class="fa fa-trash">删除</i></el-button>

      </el-button-group>

      <el-table :data="tableData"
                border
                stripe
                style="width :100%;height: 60%">
        <el-table-column
          prop="name"
          label="商户负责人"
          width="180"
        ></el-table-column>
        <el-table-column
          prop="phone"
          label="商户电话"
        ></el-table-column>
        <el-table-column
          prop="address"
          label="商户地址">
        </el-table-column>
        <el-table-column
          prop="type.name"
          label="所属类别"
        ></el-table-column>
      </el-table>

      <el-button-group>
        <el-button type="primary" icon="el-icon-arrow-left">上一页</el-button>

        <el-button type="primary">下一页<i class="el-icon-arrow-right el-icon--right"></i></el-button>
      </el-button-group>

    </el-row>

    <el-dialog
      title="用户添加"
      :visible.sync="dialogVisible"
      width="30%"
      :before-close="handleClose">
      <el-form>
        <el-form-group>
          <el-form-item label-width="80px" label="商户负责人">
            <el-input v-model="merchants.name"/>
          </el-form-item>
        </el-form-group>
        <el-form-group>
          <el-form-item label-width="80px" label="商户电话">
            <el-input v-model="merchants.phone"/>
          </el-form-item>
        </el-form-group>
        <el-form-group>
          <el-form-item label-width="80px" label="商户地址">
            <el-input v-model="merchants.address"/>
          </el-form-item>
        </el-form-group>
        <el-form-group>
          <el-form-item label-width="80px" label="所属类别">
            <!--<el-input v-model="user.permission">-->
            <!--选择器开始-->
            <el-select v-model="merchants.type" placeholder="请选择">
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.label">
              </el-option>
            </el-select>
          </el-form-item>
        </el-form-group>

      </el-form>

      <span class="dialog-footer" slot="footer" >
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button @click="sumbmitHandle" type="primary" >确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
  export default {
    name: "merchants", data(){
      return{
        //选项
        options: [{
          value: '选项1',
          label: '社区驿站'
        }, {
          value: '选项2',
          label: '校园驿站'
        }, {
          value: '选项3',
          label: '菜鸟乡村'
        }
        ],
        value:'',

        tableData:[],
        dialogFormVisible: false,
        formLabelWidth: '120px',
        merchants:{
          name:'',
          phone:'',
          address:'',
          type:''
        }
      }
    },mounted() {
      /*挂载结束之后*/
      var _this=this;
      this.axios({
        url:'http://localhost:3000/merchants/list',
        method:'get'
      }).then(function (res) {
        _this.tableData=res.data;
      })
    },
    methods:{
      btnAddClick(){
        this.dialogFormVisible = true;
      },
      handleClose(){
        this.dialogFormVisible=false;
      },
      sumbmitHandle(){
        var _this=this;
        this.axios({
          url:'http://127.0.0.1:3000/merchants/add',
          method:'get',
          params:{
            name:this.merchants.name,
            phone:this.merchants.phone,
            address:this.merchants.address,
            type:this.merchants.type
          }
        }).then(function (res) {
          if(res.data.flag){
            _this.$message('添加成功')
            _this.dialogFormVisible=false;
          }else{
            alert('添加失败');
          }
        })
      }
    }
  }
</script>

<style scoped>

</style>
